package qiche.mock

import com.qiche.common.SparkBase
import com.qiche.model.OdsTeacherInfo
import org.apache.spark.sql.SparkSession

object OdsTeacherInfoMock extends SparkBase {

  def execute(spark: SparkSession): Unit = {
    import spark.implicits._

    val base = spark.read.textFile("src/jiaoshi.txt")
    base.map(x => {
      val array = x.split(",")

      new OdsTeacherInfo(
        array(0).trim,
        array(1).trim
      )
    }).toDF().createTempView("ods_teacher_info_view")

    spark.sql(
      s"""insert into table pingtai.ods_teacher_info select * from ods_teacher_info_view""".stripMargin)
  }


  def main(args: Array[String]): Unit = {
    System.setProperty("HADOOP_USER_NAME", "hadoop")
    System.setProperty("HIVE_USER_NAME", "hadoop")
    val spark = getContextLocal(this.getClass.getName.split('.').last)
    execute(spark)
    spark.stop()
  }
}



